<%@page import="com.right.entity.Foods"%>
<%@page import="java.util.List"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<meta name="description" content="">
<meta name="author" content="">
<link rel="icon" href="../../favicon.ico">

<title>Dashboard Template for Bootstrap</title>

<!--1. Bootstrap core CSS -->
<link href="dist/css/bootstrap.min.css" rel="stylesheet">



<!--2. Custom styles for this template -->
<link href="css/dashboard.css" rel="stylesheet">

</head>

<body>

	<jsp:include page="nav.html"></jsp:include>

	<div class="container-fluid">
		<div class="row">
			<div class="col-sm-3 col-md-2 sidebar">
				<ul class="nav nav-sidebar">
					<li><a href="s-user.jsp">商家信息</a></li>
					<li><a href="s-orders.jsp">订单列表</a></li>
					<li><a href="s-comment.jsp">评价列表</a></li>
					<li><a href="FoodsServlet?op=selectByPage">菜品列表</a></li>
					<li class="active"><a href="s-foodsadd.jsp">增加菜品</a></li>
				</ul>

			</div>
			<div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">


				<h2 class="sub-header">增加菜品</h2>

				<div class="row clearfix">
					<div class="col-md-8 column">
						<%-- <%=request.getAttribute("msg") == null ? "" : request.getAttribute("msg")%> --%>
						<form class="form-horizontal" role="form" action="FoodsServlet"
							method="post" >
							<div class="form-group">
								<label for="inputEmail3" class="col-sm-2 control-label">菜品名称</label>
								<div class="col-sm-10">
									<input type="text" class="form-control" id="foodsname"
										name="foodsname" required="required" />
									<!-- ajax检查的按钮 -->
									<span id="msg"></span>
								</div>
							</div>
							<div class="form-group">
								<label for="inputPassword3" class="col-sm-2 control-label">菜品价格</label>
								<div class="col-sm-10">
									<input type="text" class="form-control" id="price"
										name="price" required="required" />
								</div>
							</div>
							<div class="form-group">
								<label for="inputPassword3" class="col-sm-2 control-label">类型编号</label>
								<div class="col-sm-10">
									<input type="text" class="form-control" id="typeid"
										name="typeid" required="required" />
								</div>
							</div>
							<div class="form-group">
								<label for="inputPassword3" class="col-sm-2 control-label">商家编号</label>
								<div class="col-sm-10">
									<input type="text" class="form-control" id="storeid"
										name="storeid" value="1" readonly="readonly" />
								</div>
							</div>
							<div class="form-group">
								<label for="inputPassword3" class="col-sm-2 control-label">菜品详情</label>
								<div class="col-sm-10">
									<input type="text" class="form-control" id="foodsstatus"
										name="foodsstatus" required="required" />
								</div>
							</div>
							<input type="hidden" name="op" value="add">

							<div class="form-group">
								<div class="col-sm-offset-2 col-sm-10">
									<button type="submit" class="btn btn-default">增加</button>
								</div>
							</div>
						</form>
					</div>
					<div class="col-md-4 column"></div>
				</div>
			</div>
		</div>
	</div>
	<!-- Bootstrap core JavaScript
    ================================================== -->
	<!--3 - js/jquery-2.0.3.js -->
	<script src="js/jquery-2.0.3.js"></script>
	<!--4 - ootstrap.min.js -->
	<script src="dist/js/bootstrap.min.js"></script>
	<script>
		var msg = "";
		$(function() {
			//文本框事件 ： 失去焦点
			$("#foodsname").blur(function() {
				ajaxName();
			});
		});
		function ajaxName() {
			$.ajax({
				//key:value
				url : "FoodsServlet",
				type : "get",
				data : {
					typename : $("#foodsname").val(),
					op : "ajaxtypename"
				},
				success : function(data) {
					console.log("data->msg: " + data);
					msg = data;
					//$("#msg")得到页面上id为msg的哪个span
					$("#msg").html(data);
				},
				dataType : "json"
			});
		}
		function check() {
			var typename = document.getElementById("foodsname").value;
			//以空格开头并且已空格结尾，中间多次或者零次空格
			var reg = /^[\s]*$/;
			var flag = reg.test(typename);
			//若结果为true则表示全为空格或者为空
			if (flag) {
				alert("类型名称不能为空！");
				return false;
			}
			//点击增加按钮的时候，都要判断是否有重复的内容(类型重复)
			//重复校验和判断
			if (msg == "类型名称不存在,可以使用.") {
				return true;
			} else {
				return false;
			}
		}
	</script>


</body>
</html>